<?php
namespace app\test\controller;

use app\home\common\Common;
use app\infrastructure\uri\Uri;
use think\Controller;
use think\Db;
use think\Exception;

class Test extends Common
{

    /**
    @SWG\Get(
    path="/pets",
    description="Returns all pets from the system that the user has access to",
    operationId="findPets",
    produces=
    Unknown macro: {"application/json", "application/xml", "text/xml", "text/html"}
    ,
    @SWG\Parameter(
    name="tags",
    in="query",
    description="tags to filter by",
    required=false,
    type="array",
    @SWG\Items(type="string"),
    collectionFormat="csv"
    ),
    @SWG\Parameter(
    name="limit",
    in="query",
    description="maximum number of results to return",
    required=false,
    type="integer",
    format="int32"
    ),
    @SWG\Response(
    response=200,
    description="pet response",
    @SWG\Schema(
    type="array",
    @SWG\Items(ref="#/definitions/pet")
    ),
    ),
    @SWG\Response(
    response="default",
    description="unexpected error",
    @SWG\Schema(
    ref="#/definitions/errorModel"
    )
    )
    )
     */
    public function index()
    {
//         $da=Db::table('da_partdata')->where('mass_date','2017-09-25')->select();

//        pcntl_fork();
//        $city_name=Db::table('da_partdata')->distinct(true)->field('park_name')->column('park_name');
//        $city_name=Db::table('da_partdata')->distinct(true)->field('park_name')->select();
//        dd($city_name);
//        foreach($city_name as $k=>$v){
//            $data['park_name']=$v;
////            dd($data);die;
//            Db::table('da_parkname')->insert($data);
//        }
//        <meta http-equiv="X-Frame-Options" content="">
//        header("Access-Control-Allow-Origin: *");
//        header("X-Frame-Options:ALLOW-FROM *");
//        $str = file_get_contents('http://data.etcp.cn/map');
//        file_put_contents('./a.html', $str);
//        $this->assign('str', $str);
//        return view();

    }
    function err()
    {
//        ob_clean();
        return (json_encode(['valid' => 0, 'msg' => '678']));
    }
    function excelcreate()
    {
            set_time_limit(0);
            //查询数据
            $data = Db::table('odps_table_info')
                ->limit(100000)
                ->select();

//            array_unshift($data, $head);  //添加表头
            $file_name = '用户详细信息';         //excel文件名
            //将用户信息组装成表格导出到excel中
            $str = ''; //初始化
            //输出表头
            $str .= '<table border="1">
                    <tr>
                        <td colspan="'.count($data[0]).'" align="center" style="font-size:16px; height:32px; font-weight:bold">'.$file_name.'</td>
                    </tr>';
            //循环输出行
            foreach($data as $v1) {
                $str .= '<tr>';
                //循环输出列
                foreach($v1 as $v2) {
                    $str .= '<td style="vnd.ms-excel.numberformat:@">'.$v2.'</td>';
                }
                $str .= '</tr>';
            }
            $str .=    '</table>';
            //转换为GBK编码
            $str = iconv("UTF-8","GBK",$str);
            //输出
            header('Content-Length: '.strlen($str));
            header("Content-type:application/vnd.ms-excel");
            header("Content-Disposition:filename={$file_name}.xls");
           file_put_contents('./ccc.xlsx',$str);
    }


}

